package com.atguigu.mapreduce.sorting;

import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Reducer;

import java.io.IOException;

public class FlowCountReducer extends Reducer<FlowBean, Text, Text, FlowBean> {
    private FlowBean outV = new FlowBean();

//    @Override
//    protected void reduce(Text key, Iterable<FlowBean> values, Reducer<Text, FlowBean, Text, FlowBean>.Context context) throws IOException, InterruptedException {
//        int totalUpFlow = 0;
//        int totalDownFlow = 0;
//        int totalSumFlow = 0;
//        for (FlowBean value : values) {
//            totalUpFlow += value.getUpFlow();
//            totalDownFlow += value.getDownFlow();
//            totalSumFlow += value.getSumFlow();
//        }
//        outV.setUpFlow(totalUpFlow);
//        outV.setDownFlow(totalDownFlow);
//        outV.setSumFlow(totalSumFlow);
//        context.write(key, outV);
//    }

    @Override
    protected void reduce(FlowBean key, Iterable<Text> values, Reducer<FlowBean, Text, Text, FlowBean>.Context context) throws IOException, InterruptedException {
        for (Text value : values) {
            context.write(value, key);
        }
        super.reduce(key, values, context);
    }
}
